# -*- coding: utf-8 -*-
# @Time    : 2021/10/25 11:58 上午
# @Author  : CHENlj
# @File    : test1_task.py

from Common.Request import Request
from Common import Public
from Common.ApiAdress import GetIndexData
import allure, pytest, json


@allure.feature('请求首页数据模块')
class TestGetIndexData:
    """
    请求首页数据
    """

    @allure.step('断言信息：')
    def step_with_assert_info(self, response, expected):
        pass

    @allure.step('执行步骤：')
    def step_introduce(self, first=None, second=None, third=None):
        pass

    @allure.testcase(url='#', name=GetIndexData)
    @allure.description('获取用户首页数据')
    @allure.story('请求首页数据')
    @allure.title("请求首页数据")
    @pytest.mark.usefixtures('action')
    def test_get_index_data(self, action):
        headers = Public.create_headers(GetIndexData)

        data = {
            "DeviceId": Public.DeviceId,
        }

        data = json.dumps(data)

        res = Request.post_request(GetIndexData, data=data, headers=headers)

        # self.step_introduce('请求首页数据链接', '发起post请求', '查看结果')
        self.step_with_assert_info('请求返回体中"STATUS"为:, '+str(res.json()['STATUS']), '预期结果为: 2000')
        allure.attach(data, '请求数据:', allure.attachment_type.JSON)
        allure.attach(json.dumps(res.json(), indent=1, ensure_ascii=False), '返回数据:', allure.attachment_type.JSON)
        action.assert_code(res.json()['STATUS'], 2000)


if __name__ == '__main__':
    pytest.main(['-s', '-q', "test1_task.py"])
    # t = TestGetIndexData()
    # t.test_get_index_data()
